"""CopyRight(C) From WangShiheng"""
# Author: WangShiheng
# Package: BaseLib.util.OS.Thread.ThreadPool
from BaseLib.util.base.Pool.base import BasePool


class ThreadPool(BasePool):

    def Add(self, obj):
        obj.start()
        super().Add(obj)

    def wait(self):
        for Thread in self.pool:
            Thread.join()

    def __enter__(self):
        return super().__enter__()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.wait()
